<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CommonAction
 *
 * @author Administrator
 */
class CommonAction extends BaseAction {
    //put your code here
    public function getArea(){
        $name = isset($_GET['term']) ? trim($_GET['term']) : '';
        if($name==''){
            return fasle;
        }
        $m=new Model();
        $sql="SELECT id,title,ptitle FROM elssns.ts_network where `types`=2 and (title like '$name%' or pinyin1 like '$name%' or pinyin2 like '$name%');";
        $list=$m->query($sql);
        $arr=array();
        foreach ($list as $value) {
            $arr[]=$value['title'].'-'.$value['ptitle'].'('.$value['id'].')';
        }
        echo json_encode($arr);
        exit();
    }
    public function gethospital(){
        $name = isset($_GET['term']) ? trim($_GET['term']) : '';
        //$name=  rawurldecode($name);
        $area = isset($_GET['area']) ? trim($_GET['area']) : '';
        $areaid = 0;
        $where = '1';
        if ($area != '') {
            $areaid = getAreaId($area);
            $where.=' and city_id=' . $areaid;
        }
        if ($name != '') {
            $where.=' and (hospital_name like \'%' . $name . '%\' or pinyin1 like \'%' . $name . '%\' or pinyin2 like \'%' . $name . '%\')'; 
        }
        $Model = new Model();
        $sql='SELECT hospital_id,hospital_name,area_name FROM `ts_base_hospital` WHERE ' . $where . ' LIMIT 20';
        $list = $Model->query($sql);
        $arr=array();
        foreach ($list as $value) {
            $arr[]=$value['hospital_name'].'-'.$value['area_name'].'('.$value['hospital_id'].')';
        }
        echo json_encode($arr);
        exit();
    }
    public function getKeshi(){
        $hospital_id=  isset($_GET['id'])?getHospitalId($_GET['id']):0;
        $name = isset($_GET['term']) ? trim($_GET['term']) : '';
        $mod=new Model();
        $sql='select keshi_id,keshi_name from ts_base_hospital_keshi where hospital_id='.$hospital_id.' and (pinyin1 like \'%'.$name.'%\' or pinyin2 like \'%'.$name.'%\' or keshi_name like \'%'.$name.'%\')';
        $list=$mod->query($sql);
        $arr=array();
        foreach ($list as $value) {
            $arr[]=$value['keshi_name'].'('.$value['keshi_id'].')';
        }
        echo json_encode($arr);
        exit(); 
    }
    public function getDoctor(){
        $hospital_id=  isset($_GET['id'])?getHospitalId($_GET['id']):0;
        $name = isset($_GET['term']) ? trim($_GET['term']) : '';
        //$name=  rawurldecode($name);
        $mod=new Model();
        $sql='select doctor_id,doctor_name from ts_base_hospital_doctor where hospital_id='.$hospital_id.' and (pinyin1 like \'%'.$name.'%\' or pinyin2 like \'%'.$name.'%\' or doctor_name like \'%'.$name.'%\')';
        $list=$mod->query($sql);
        $arr=array();
        foreach ($list as $value) {
            $arr[]=$value['doctor_name'].'('.$value['doctor_id'].')';
        }
        echo json_encode($arr);
        exit(); 
    }
    public function getbDisease(){
        $name = isset($_GET['term']) ? trim($_GET['term']) : '';
        //$name=  rawurldecode($name);
        $mod=new Model();
        $sql='select disease_id,disease_name from ts_base_disease where pinyin1 like \'%'.$name.'%\' or pinyin2 like \'%'.$name.'%\' or disease_name like \'%'.$name.'%\'';
        $list=$mod->query($sql);
        $arr=array();
        foreach ($list as $value) {
            $arr[]=array('id'=>$value['disease_id'],'value'=>$value['disease_name']);
        }
        echo json_encode($arr);
        exit(); 
    } 
}
